package main

import (
	"fmt"
	"com.dw/demo1/concurrent/pipelinedemo"
	"os"
)

func main() {
	filename := "intsvalus.txt"
	nums := 10000

	valus := pipelinedemo.RandomIntValus(nums)
	//readChal(valus)
	file, e := os.Create(filename)
	if (e == nil) {
		pipelinedemo.WriteFile(file, valus)
	} else {
		e.Error()
	}
	defer file.Close()
	//读文件
	open, i := os.Open(filename)
	if (i != nil) {
		i.Error()
	}
	b := pipelinedemo.ReadFile(open)
	readChal(b)
}

//只读取前100个数据
func readChal(in <-chan int) {
	n := 0
	for {
		if (n > 100) {
			break
		}
		v, s := <-in
		if (s) {
			fmt.Println(v)
		} else {
			break
		}
		n++
	}
}
func demo1() {
	//arr := []int{1, 8, 45, 7, 3, 6, 7, 34, 556}
	//a := pipelinedemo.ArraySource(arr)
	//for {
	//	v, state := <-a
	//	if (state) {
	//		fmt.Println(v)
	//	} else {
	//		break
	//	}
	//}
}
func demo2() {
	arr1 := []int{1, 8, 45, 7}
	arr2 := []int{3, 6, 7, 34, 556}

	fmt.Println("-------------------------------")
	//b := pipelinedemo.ImMenSort(pipelinedemo.ArraySource_chan(arr))
	c := pipelinedemo.MergeInMen(pipelinedemo.ArraySource_chan(arr1), pipelinedemo.ArraySource_chan(arr2))
	for {
		v, state := <-c
		if (state) {
			fmt.Println(v)
		} else {
			break
		}
	}
}
